package com.zx.mes.hyl.controller.leave;

import com.zx.mes.hyl.common.msg.ObjectRestResponse;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.activiti.engine.RepositoryService;
import org.activiti.engine.RuntimeService;
import org.activiti.engine.repository.DeploymentQuery;
import org.activiti.engine.runtime.ProcessInstance;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * 请假处理
 * @author hyl
 * @date 2018-5-23
 */
@Api(tags = "请假处理")
@RestController
@RequestMapping("/leave")
public class LeaveController {

    @Autowired
    private RuntimeService runtimeService;

    @Autowired
    private RepositoryService repositoryService;

    @ApiOperation("启动一个部署实例")
    @PostMapping("/start/{id}")
    public ObjectRestResponse<String> startProcessInstanceByKey(@ApiParam("流程部署ID") @PathVariable String id,
                                                                @ApiParam("启动实例时,所带参数") Map<String, Object> params){
        ProcessInstance processInstance = runtimeService.createProcessInstanceQuery()
                .deploymentId(id)
                .singleResult();

        runtimeService.startProcessInstanceByKey(processInstance.getProcessDefinitionKey());
        return new ObjectRestResponse<String>().rel(true);
    }

//    List<Task> tasks = taskService.createTaskQuery()
//            .taskAssignee("kermit")
//            .processVariableValueEquals("orderId", "0815")
//            .orderByDueDate().asc()
//            .list();
}
